package com.fl.rabbitmq.order;

import cn.hutool.core.util.IdUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {
    @Autowired
    private RabbitTemplate template;
    /**
     * @author fanlei
     * 创建订单
     * @Date 2021/3/17 16:25
     * @Param [uuid, producerid, num]
     * @return void
     **/
    public void makeOrder(String uuid,String producerid,int num){
        String OrderId = IdUtil.simpleUUID();
        System.out.println("订单产生成功！"+OrderId);
        String ExchangeName = "fanout_order_echange";
        String reoutKey = "";
        //参数1：交换机名称 参数2：reoutkey/queue名称 参数3：传输内容
        template.convertAndSend(ExchangeName,reoutKey,OrderId);

    }

    public void makeOrderDrect(String uuid,String producerid,int num){
        String OrderId = IdUtil.simpleUUID();
        System.out.println("订单产生成功！"+OrderId);
        String ExchangeName = "direct_order_echange";
        String reoutKey = "";
        //参数1：交换机名称 参数2：reoutkey/queue名称 参数3：传输内容
        template.convertAndSend(ExchangeName,"sms",OrderId);
        template.convertAndSend(ExchangeName,"email",OrderId);

    }

    public void makeOrderTopic(String uuid,String producerid,int num){
        String OrderId = IdUtil.simpleUUID();
        System.out.println("订单产生成功！"+OrderId);
        String ExchangeName = "topic_order_echange";
        String reoutKey = "com.sms.xxx";
        //参数1：交换机名称 参数2：reoutkey/queue名称 参数3：传输内容
        template.convertAndSend(ExchangeName,reoutKey,OrderId);

    }
}
